package cn.zn.modules.appoin.controller;

import cn.zn.framework.common.utils.PageInUtils;
import cn.zn.framework.common.utils.PageUtils;
import cn.zn.framework.common.utils.R;
import cn.zn.modules.appoin.entity.AppoinTimeRuleEntity;
import cn.zn.modules.appoin.service.AppoinTimeRuleService;
import cn.zn.modules.zzsys.inter.SysRoleInter;
import cn.zn.modules.zzsys.inter.annotation.Login;
import cn.zn.modules.zzsys.inter.annotation.LoginUser;
import cn.zn.modules.zzsys.inter.dto.LoginUserDTO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 规则：总
 *
 * @author zn
 * @email zhunahao@qq.com
 * @date 2020-09-01 14:15:28
 */
@RestController
@RequestMapping("appoin/appointimerule")
public class AppoinTimeRuleController {
    @Autowired
    private AppoinTimeRuleService appoinTimeRuleService;
    @Autowired
    private SysRoleInter sysRoleInter;

    /**
     * 列表
     */
    @RequestMapping("/roleList")
    @Login
    public R roleList(@LoginUser LoginUserDTO loginUserDTO) {
        return R.ok().put("list", sysRoleInter.queryRoleList("", false));
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("appoin:appointimerule:list")
    public R list(PageInUtils<AppoinTimeRuleEntity> pageIn) {

        AppoinTimeRuleEntity appoinTimeRule = new AppoinTimeRuleEntity();
        PageUtils pageUtils = appoinTimeRuleService.queryPage(appoinTimeRule, pageIn.getPageObj());

        return R.ok().put("page", pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("appoin:appointimerule:info")
    public R info(@PathVariable("id") String id) {
        AppoinTimeRuleEntity appoinTimeRule = appoinTimeRuleService.getById(id);

        return R.ok().put("appoinTimeRule", appoinTimeRule);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("appoin:appointimerule:save")
    public R save(@RequestBody AppoinTimeRuleEntity appoinTimeRule) {
        appoinTimeRuleService.saveRule(appoinTimeRule);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("appoin:appointimerule:update")
    public R update(@RequestBody AppoinTimeRuleEntity appoinTimeRule) {
        appoinTimeRuleService.updateById(appoinTimeRule);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("appoin:appointimerule:delete")
    public R delete(@RequestBody String[] ids) {
        appoinTimeRuleService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @PostMapping("/state/{id}")
    public R state(@PathVariable String id) {
        appoinTimeRuleService.changeState(id);
        return R.ok();
    }

}
